package br.com.ericogr.hanoi.entidade;

import java.util.List;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import br.com.ericogr.hanoi.controle.EventoControle;
import br.com.ericogr.hanoi.controle.EventoControle.Touch;

public class EntidadeFundo implements Entidade {
    private static final long serialVersionUID = 1L;
    
    private transient int mScreenWidth;
    private transient int mScreenHeight;
    private transient Paint mPaint;
    private transient int mBaseSelecionada;
    
    public EntidadeFundo() {
        mPaint = new Paint();
        mBaseSelecionada = -1;
    }
    
    @Override
    public void configuraResolucao(int screenWidth, int screenHeight) {
        mScreenWidth = screenWidth;
        mScreenHeight = screenHeight;
    }

    @Override
    public void processamentoLogico(List<Entidade> entidade) {
    }

    @Override
    public void processamentoGrafico(Canvas canvas) {
        int w1 = mScreenWidth / 3;
        
        mPaint.setColor(Color.WHITE);
        mPaint.setStyle(Style.FILL_AND_STROKE);
        
        if (mBaseSelecionada == -1) {
            canvas.drawRect(0, 0, mScreenWidth, mScreenHeight, mPaint);
        }
        else {
            int offSet = mBaseSelecionada * (mScreenWidth / 3);
            
            mPaint.setColor(Color.LTGRAY);
            canvas.drawRect(0, 0, mScreenWidth, mScreenHeight, mPaint);
            
            mPaint.setColor(Color.WHITE);
            canvas.drawRect(offSet, 0, (mScreenWidth / 3) + offSet, mScreenHeight, mPaint);
        }
        
        mPaint.setColor(Color.GRAY);
        mPaint.setStyle(Style.STROKE);
        mPaint.setPathEffect(new DashPathEffect(new float[] {10, 20}, 0));
        canvas.drawLine(w1, 0, w1, mScreenHeight, mPaint);
        canvas.drawLine(w1 * 2, 0, w1 * 2, mScreenHeight, mPaint);
    }

    @Override
    public void processamentoEvento(EventoControle eventoControle) {
        if (eventoControle.getTouch() == Touch.PRESSIONADO || eventoControle.getTouch() == Touch.MOVENDO) {
            int x = (int)eventoControle.getX();
            int w1 = mScreenWidth / 3;
            
            mBaseSelecionada = x / w1;
        }
        else if (eventoControle.getTouch() == Touch.SOLTO) {
            mBaseSelecionada = -1;
        }
    }

    @Override
    public void setJogoListener(JogoListener jogoListener) {
    }

}